<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<title>系统后台 - {$Think.config.INTENDANT_NAME} - by HemaCMS</title>
    <link href="__INTENDANT__/css/admin_style.css" rel="stylesheet" />
    <script src="__COMMON__/jquery.js"></script>
    <script src="__COMMON__/jquery.cookie.js"></script>
    <script src="__COMMON__/jquery.validate.min.js"></script> <!--表单验证-->
    <script src="__COMMON__/layer/layer.js"></script>
    <script src="__INTENDANT__/js/iteny.intendant.js"></script> <!--公共easyui JS-->
    <link href="__INTENDANT__/css/iteny.css" rel="stylesheet" />

</head>
<body class="J_scroll_fixed">
<div class="wrap J_check_wrap">
  	<div class="nav">
	    <ul class="cc">
	        <li><a href="{:U('Site/role')}">角色管理</a></li>
	        <li><a href="{:U('Site/addRole')}">添加角色</a></li>
	    </ul>
	</div>
  <div class="table_list">
    <div class="h_a">角色信息</div>
    <form class="J_ajaxForm" action="{:U("Site/editRole")}" name="editRole" method="post" id="editRole">
    <input type="hidden" name="editRole" value="editRole" />
    <input type="hidden" name="id" value="{$role.id}" />
    <div class="table_full">
        <table width="100%">

          <tr>
            <th width="100">角色名称</th>
            <td><input type="text" name="title" value="{$role.title}" class="input length_5" id="title"></input></td>
          </tr>
          <tr>
            <th width="100">角色排序</th>
            <td><input type="text" name="sort" value="{$role.sort}" class="input length_2" id="sort"></input></td>
          </tr>
          <tr>
            <th>角色描述</th>
            <td><textarea name="remark" rows="2" cols="20" id="remark" class="inputtext" style="height:100px;width:500px;">{$role.remark}</textarea></td>
          </tr>
          <tr>
            <th>是否启用</th>
            <td><input type="radio" name="status" value="1"  <if condition="$role['status'] eq 1">checked</if>>启用<label>  &nbsp;&nbsp;&nbsp;&nbsp;<input type="radio" name="status" value="0" <if condition="$role['status'] eq 0">checked</if>>禁止</label></td>
          </tr>
        </table>
        <!-- <input type="hidden" name="id" value="{$data.id}" /> -->

    </div>
    <div class="btn_wrap">
        <div class="btn_wrap_pd">
          <button class="btn btn_submit mr10 J_ajax_submit_btn" type="submit">提交</button>
        </div>
      </div>
    </form>
  </div>
</div>
<script type="text/javascript">
var roledizhi = "{:U('Site/role')}";
var checkRoleTitle = "{:U('SiteCom/checkRoleTitle',array('id'=>$role['id'],'title'=>$role['title']))}";
$(function(){
  jQuery.validator.addMethod("chinaese", function(value, element) {
  var chinaese = /^[\u4e00-\u9fa5]+$/;
  return this.optional(element) || (chinaese.test(value));
  }, "只能输入中文");
  $('form[name=editRole]').validate({
    errorElement : 'span',
    validClass: "success",  //非常重要
    success : function (label) {
      label.addClass('success');
    },

        rules : {
                title : {
                    required : true,
                    chinaese : true,
                    remote : {
                     url : checkRoleTitle,
                     type : 'post',
                     dataType : 'json',
                     data : {
                       title : function(){
                         return $('#title').val();
                       }
                     }
                    }
                },

            },
        messages : {
                title : {
                    required : "请输入角色名称",
                    remote : '角色名称已存在'
                },

            },
            submitHandler: function(form)
            {
              if($('.J_ajax_submit_btn').attr("disabledSubmit")){
              $('.J_ajax_submit_btn').text('请勿重复提交...').prop('disabled', true).addClass('disabled');
              return false;
          }
        $('.J_ajax_submit_btn').attr("disabledSubmit",true);
              var param = $('form[name=editRole]').serialize();
              $.ajax({
          url: $('form[name=editRole]').attr('action'),
          dataType:'json',
          type:'POST',
          data:param,
          success: function(data) {
            if (data=='-20') {
              ITENY.alert('提示','修改角色成功',1,'5000');
              setTimeout(function(){
                          window.location.href=roledizhi;
                      },3000);
            }
            else if(data=='-3')
            {
              ITENY.alert('提示','角色名称被占用',2,'5000');
              $('.J_ajax_submit_btn').text('添加').removeProp('disabled').removeClass('disabled');
              $('.J_ajax_submit_btn').attr("disabledSubmit",'');
            }
            else if(data=='-4')
            {
              ITENY.alert('提示','角色名称必须是中文',2,'5000');
              $('.J_ajax_submit_btn').text('添加').removeProp('disabled').removeClass('disabled');
              $('.J_ajax_submit_btn').attr("disabledSubmit",'');
            }

            else {
              ITENY.alert('提示','未知错误，请联系管理员！',2,'5000');
              $('.J_ajax_submit_btn').text('添加').removeProp('disabled').removeClass('disabled');
              $('.J_ajax_submit_btn').attr("disabledSubmit",'');
            }
          }
        });

            }

  });
});
</script>
</body>
</html>